<!--<script src="/static/vendors/editor.md/lib/codemirror/codemirror.min.js">
</script>
<script src="/static/vendors/editor.md/lib/codemirror/modes.min.js"></script>
<script src="/static/vendors/editor.md/lib/codemirror/addons.min.js"></script>
<script src="/static/vendors/editor.md/lib/marked.min.js"></script>
<script src="/static/vendors/editor.md/lib/prettify.min.js"></script>-->
<script>
    var editor = null;
    // markdown编辑器初始化
    $(function() {
        editor = editormd("editormd", {
            autoLoadModules: false // Manually load modules
        });
        // editor = editormd("editormd", {
        //     path: "/static/vendors/editor.md/lib/" // Autoload modules mode, codemirror, marked... dependents libs path
        // });
    });

    //保存博文草稿
    function save(status) {

        var title = $('#title').val(); //博文标题
        var articleId = $('#articleId').val(); //博文ID
        var excerpt = $('#excerpt').val(); //博文简述

        $(this).bjuiajax('doAjax', {
            url: '/api/article/edit',
            type: "post",
            data: {
                id: articleId,
                markdown: editor.getMarkdown(),
                html: editor.getPreviewedHTML(),
                title: title,
                excerpt: excerpt,
                status: status,
                published_at:$('#article_published_at').val(),
                author_id: 1
            },
            callback: function(result) {
                if (result.statusCode === '200') {
                    $(this).alertmsg('info', result.message);
                    $(this).navtab({
                        id: 'article_edit',
                        url: '/admin/article/edit?articleId=' + result.id,
                        title: '编辑博文'
                    });
                    editor.watch(); //解决有时候预览窗口空白问题
                    $(this).dialog('closeCurrent');
                }
            }
        })
    }

    /**
     * @description文件上传完回调
     * @params data上传的文件对象 result上传完毕后端返回对象
     * @return 
     */
    function pic_upload_success(data, result) {

        $('#article_img').attr('src', "/static/upload/" + JSON.parse(result).filename);
    }
</script>
<div class="bjui-pageHeader">
    <input type="text" class="input-ng" id="title" placeholder="博文标题" style="width:500px;font-weight:bold" value="<%=article.title%>">
    <div class="pull-right">
        <button type="button" class="btn-green" data-toggle="dialog" data-fresh="false" data-width="800" data-height="550" data-id="article_setting" data-mask="true" data-target="#doc-dialog-target" data-title="博文设置">博文设置</button>
    </div>
</div>
<div class="bjui-pageContent">
    <!--博文主键-->
    <input type="hidden" name="id" id="articleId" value="<%=article.id%>">
    <!-- 内容区 -->
    <div id="editormd">
        <textarea id="markdown"><%=article.markdown%></textarea>
    </div>
    <div id="doc-dialog-target" data-noinit="false" class="hide">
        <table class="table table-condensed table-hover">
            <tbody>
                <tr>
                    <td colspan="2">
                        <label for="j_dialog_image" class="control-label x90">博文图片：</label>
                        <div style="display: inline-block; vertical-align: middle;">
                            <div id="j_custom_pic_up" data-toggle="upload" data-uploader="/api/file/upload" data-file-size-limit="1024000000" data-file-type-exts="*.jpg;*.png;*.gif;*.mpg" data-multi="false" data-on-upload-success="pic_upload_success" data-icon="cloud-upload"></div>
                            <input type="hidden" name="custom.pic" value="" id="j_custom_pic">
                            <img id="article_img" src="" width="200" height="100">
                            <span id="j_custom_span_pic"></span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <label for="excerpt" class="control-label x90">博文简述：</label>
                        <textarea name="excerpt" id="excerpt" data-toggle="autoheight" cols="60" value="" rows="4"><%=article.excerpt%></textarea>
                    </td>
                </tr>

                <tr>
                    <td colspan="2">
                        <label for="j_dialog_publishd_at" class="control-label x90">发布日期：</label>
                        <input type="text" data-pattern="yyyy-MM-dd HH:mm:ss" id="article_published_at" value="<%=article.published_at%>" data-toggle="datepicker">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <label for="j_dialog_tag" class="control-label x90">博文标签：</label>
                        <input type="text" id="article_tags" size="60">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <label for="j_dialog_publish_by" class="control-label x90">博文作者：</label>
                        <input type="text" id="author_id" size="60">
                    </td>
                </tr>
            </tbody>
        </table>
        <div class="bjui-pageFooter">
            <ul>
                <li><button type="button" class="btn-close" data-icon="close">取消</button></li>
                <li><button type="button" class="btn-default" data-icon="save" onclick="save('draft')">保存草稿</button></li>
                <li><button type="button" class="btn-success" data-icon="save" onclick="save('published')">立即发布</button></li>
            </ul>
        </div>
    </div>
</div>